'''
Description: 
Author: Zilu
Date: 2021-11-08 15:54:30
Version: 
LastEditTime: 2021-11-08 16:57:08
LastEditors: Zilu
'''

class MyDict(dict):
    '''
    Simple dict but support access as x.y style:

    >>> d1 = MyDict()
    >>> d1['x'] = 100
    >>> d1.x
    100
    >>> d1.y = 200
    >>> d1['y']
    200
    >>> d2 = MyDict(a=1, b=2, c='3')
    >>> d2.c
    '3'
    >>> d2['empty']
    Traceback (most recent call last):
        ...
    KeyError: 'empty'
    >>> d2.empty
    Traceback (most recent call last):
        ...
    AttributeError: 'MyDict' object has no attribute: 'empty'
    '''
    def __init__(self, **kw) -> None:
        super().__init__(**kw)

    def __getattr__(self, value):
        try:
            return self[value]
        except:
            raise AttributeError("'MyDict' object has no attribute: '%s'" % value)

    def __setattr__(self, key, value) -> None:
        self[key] = value

if __name__ == '__main__':
    import doctest
    doctest.testmod()

